﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;

using ARogueBeta;
using ARogueBeta.Helpers;

using CommonBehaviors.Actions;

using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.POI;
using Styx.CommonBot.Routines;
using Styx.Helpers;
using Styx.Pathing;
using Styx.WoWInternals;
using Styx.WoWInternals.World;
using Styx.WoWInternals.WoWObjects;
using Styx.TreeSharp;
using Action = Styx.TreeSharp.Action;

namespace ARogueBeta
{
    public partial class ARForm : Form
    {
        
        public ARForm()
        {
            InitializeComponent();
        }

        private void Form_Load(object sender, EventArgs e)
        {
            ARSettings.Instance.Load();

            AT.Checked = ARSettings.Instance.ArcaneTorrent;
            BK.Checked = ARSettings.Instance.Berserking;
            BF.Checked = ARSettings.Instance.BloodFury;
            RB.Checked = ARSettings.Instance.RocketBarrage;

            EA.Checked = ARSettings.Instance.ExposeArmor;
            Ki.Checked = ARSettings.Instance.Kick;
            SB.Checked = ARSettings.Instance.ShadowBlades;
            SS.Checked = ARSettings.Instance.ShadowStep;
            Va.Checked = ARSettings.Instance.Vanish;
            VD.Checked = ARSettings.Instance.Vendetta;

            eM.Checked = ARSettings.Instance.Movement;
            CDS.Checked = ARSettings.Instance.UseCDs;
            Al.Checked = ARSettings.Instance.AlwaysStealth;
            uT.Checked = ARSettings.Instance.UseTrinkets;
            uEG.Checked = ARSettings.Instance.UseEngineeringGloves;
            AE.Checked = ARSettings.Instance.AOE;
            AEAMT.Value = new decimal(ARSettings.Instance.AoeAmount);

            MHP.Text = ARSettings.Instance.MHPoison;
            OHP.Text = ARSettings.Instance.OHPoison;
            MHPT.Value = new decimal(ARSettings.Instance.MHPT);
            OHPT.Value = new decimal(ARSettings.Instance.OHPT);

            Rc.Checked = ARSettings.Instance.Recuperate;
            RHP.Value = ARSettings.Instance.RHP;
            ASh.Checked = ARSettings.Instance.AShiv;

            ShD.Checked = ARSettings.Instance.ShadowDance;
            KS.Checked = ARSettings.Instance.KillingSpree;
            AR.Checked = ARSettings.Instance.AdrenalineRush;
            Sp.Text = ARSettings.Instance.Spec;

            SCP.Checked = ARSettings.Instance.SpendCP;
            eFT.Checked = ARSettings.Instance.FaceTarget;
            Ru.Checked = ARSettings.Instance.Rupture;
            Pr.Checked = ARSettings.Instance.Preparation;
            BlF.Checked = ARSettings.Instance.BladeFlurry;
            Pm.Checked = ARSettings.Instance.Premeditation;
        }

        // Vendetta
        private void VD_CheckedChanged(object sender, EventArgs e)
        {
            if (VD.Checked == true)
            {
                ARSettings.Instance.Vendetta = true;
            }
            else
            {
                ARSettings.Instance.Vendetta = false;
            }
        }

        // Berserking
        private void BK_CheckedChanged(object sender, EventArgs e)
        {
            if (BK.Checked == true)
            {
                ARSettings.Instance.Berserking = true;
            }
            else
            {
                ARSettings.Instance.Berserking = false;
            }
        }

        // Blood Fury
        private void BF_CheckedChanged(object sender, EventArgs e)
        {
            if (BF.Checked == true)
            {
                ARSettings.Instance.BloodFury = true;
            }
            else
            {
                ARSettings.Instance.BloodFury = false;
            }
        }

        // Rocket Barrage
        private void RB_CheckedChanged(object sender, EventArgs e)
        {
            if (RB.Checked == true)
            {
                ARSettings.Instance.RocketBarrage = true;
            }
            else
            {
                ARSettings.Instance.RocketBarrage = false;
            }
        }

        // AOE
        private void AE_CheckedChanged(object sender, EventArgs e)
        {
            if (AE.Checked == true)
            {
                ARSettings.Instance.AOE = true;
            }
            else
            {
                ARSettings.Instance.AOE = false;
            }
        }

        // Aoe Amount
        private void AEAMT_ValueChanged(object sender, EventArgs e)
        {
            ARSettings.Instance.AoeAmount = (int)AEAMT.Value;
        }

        // Use Cooldowns
        private void CDS_CheckedChanged(object sender, EventArgs e)
        {
            if (CDS.Checked == true)
            {
                ARSettings.Instance.UseCDs = true;
            }
            else
            {
                ARSettings.Instance.UseCDs = false;
            }
        }

        // Movement
        private void EM_CheckedChanged(object sender, EventArgs e)
        {
            if (eM.Checked == true)
            {
                ARSettings.Instance.Movement = true;
            }
            else
            {
                ARSettings.Instance.Movement = false;
            }
        }

        // Arcane Torrent
        private void AT_CheckedChanged(object sender, EventArgs e)
        {
            if (AT.Checked == true)
            {
                ARSettings.Instance.ArcaneTorrent = true;
            }
            else
            {
                ARSettings.Instance.ArcaneTorrent = false;
            }
        }

        // Kick
        private void Ki_CheckedChanged(object sender, EventArgs e)
        {
            if (Ki.Checked == true)
            {
                ARSettings.Instance.Kick = true;
            }
            else
            {
                ARSettings.Instance.Kick = false;
            }
        }

        // Vanish
        private void Va_CheckedChanged(object sender, EventArgs e)
        {
            if (Va.Checked == true)
            {
                ARSettings.Instance.Vanish = true;
            }
            else
            {
                ARSettings.Instance.Vanish = false;
            }
        }

        // Shadow Blades
        private void SB_CheckedChanged(object sender, EventArgs e)
        {
            if (SB.Checked == true)
            {
                ARSettings.Instance.ShadowBlades = true;
            }
            else
            {
                ARSettings.Instance.ShadowBlades = false;
            }
        }

        // Expose Armor
        private void EA_CheckedChanged(object sender, EventArgs e)
        {
            if (EA.Checked == true)
            {
                ARSettings.Instance.ExposeArmor = true;
            }
            else
            {
                ARSettings.Instance.ExposeArmor = false;
            }
        }

        // Use Trinkets
        private void uT_CheckedChanged(object sender, EventArgs e)
        {
            if (uT.Checked == true)
            {
                ARSettings.Instance.UseTrinkets = true;
            }
            else
            {
                ARSettings.Instance.UseTrinkets = false;
            }
        }

        // Use Engineering Gloves0
        private void uEG_CheckedChanged(object sender, EventArgs e)
        {
            if (uEG.Checked == true)
            {
                ARSettings.Instance.UseEngineeringGloves = true;
            }
            else
            {
                ARSettings.Instance.UseEngineeringGloves = false;
            }
        }

        // Always Stealth
        private void Al_CheckedChanged(object sender, EventArgs e)
        {
            if (Al.Checked == true)
            {
                ARSettings.Instance.AlwaysStealth = true;
            }
            else
            {
                ARSettings.Instance.AlwaysStealth = false;
            }
        }

        // Save Button
        private void SaveButton_Click(object sender, EventArgs e)
        {
            if ((SpellManager.HasSpell("Mutilate") && Sp.Text == "Assassination") || (SpellManager.HasSpell("Blade Flurry") && Sp.Text == "Combat") || (SpellManager.HasSpell("Backstab") && Sp.Text == "Sublety"))
            {
                ARSettings.Instance.Save();
                Logging.Write("Changing settings to match " + Sp.Text + " Spec. Please wait . . .");
                Logging.Write("Configuration Saved, thank you!");
                Close();
            }
            if (!SpellManager.HasSpell("Mutilate") && Sp.Text == "Assassination") { MessageBox.Show("Please change Spec to Assassination Ingame First. Thank You!", "Spec Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }
            if (!SpellManager.HasSpell("Blade Flurry") && Sp.Text == "Combat") { MessageBox.Show("Please change Spec to Combat Ingame First. Thank You!", "Spec Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }
            if (!SpellManager.HasSpell("Backstab") && Sp.Text == "Sublety") { MessageBox.Show("Please change Spec to Sublety Ingame First. Thank You!", "Spec Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }
        }

        private void SS_CheckedChanged(object sender, EventArgs e)
        {
            if (SS.Checked == true)
            {
                ARSettings.Instance.ShadowStep = true;
            }
            else
            {
                ARSettings.Instance.ShadowStep = false;
            }
        }

        private void MHP_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (MHP.Text == "Deadly Poison")
            { ARSettings.Instance.MHPoison = "Deadly Poison"; }
            else if (MHP.Text == "Wound Poison")
            { ARSettings.Instance.MHPoison = "Wound Poison"; }
            else
            { ARSettings.Instance.MHPoison = null; }
        }
        private void OHP_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (OHP.Text == "Crippling Poison")
            { ARSettings.Instance.OHPoison = "Crippling Poison"; }
            else if (OHP.Text == "Mind-numbing Poison")
            { ARSettings.Instance.OHPoison = "Mind-numbing Poison"; }
            else if (OHP.Text == "Leeching Poison")
            { ARSettings.Instance.OHPoison = "Leeching Poison"; }
            else
            { ARSettings.Instance.OHPoison = null; }
        }

        private void MHPT_ValueChanged(object sender, EventArgs e)
        {
            ARSettings.Instance.MHPT = (int)MHPT.Value;
        }

        private void OHPT_ValueChanged(object sender, EventArgs e)
        {
            ARSettings.Instance.OHPT = (int)OHPT.Value;
        }

        private void Rc_CheckedChanged(object sender, EventArgs e)
        {
            if (Rc.Checked == true)
            {
                ARSettings.Instance.Recuperate = true;
            }
            else
            {
                ARSettings.Instance.Recuperate = false;
            }
        }

        private void RHP_ValueChanged(object sender, EventArgs e)
        {
            ARSettings.Instance.RHP = (int)RHP.Value;
        }

        private void ASh_CheckedChanged(object sender, EventArgs e)
        {
            if (ASh.Checked == true)
            {
                ARSettings.Instance.AShiv = true;
            }
            else
            {
                ARSettings.Instance.AShiv = false;
            }
        }

        private void ShD_CheckedChanged(object sender, EventArgs e)
        {
            if (ShD.Checked == true)
            {
                ARSettings.Instance.ShadowDance = true;
            }
            else
            {
                ARSettings.Instance.ShadowDance = false;
            }
        }

        private void AR_CheckedChanged(object sender, EventArgs e)
        {
            if (AR.Checked == true)
            {
                ARSettings.Instance.AdrenalineRush = true;
            }
            else
            {
                ARSettings.Instance.AdrenalineRush = false;
            }
        }

        private void KS_CheckedChanged(object sender, EventArgs e)
        {
            if (KS.Checked == true)
            {
                ARSettings.Instance.KillingSpree = true;
            }
            else
            {
                ARSettings.Instance.KillingSpree = false;
            }
        }

        private void Sp_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Sp.Text == "Assassination")
            {
                VD.Enabled = true; AR.Enabled = false; KS.Enabled = false; BlF.Enabled = false; ShD.Enabled = false; Pm.Enabled = false;
                ARSettings.Instance.Spec = "Assassination"; }
            else if (Sp.Text == "Combat")
            {
                VD.Enabled = false; AR.Enabled = true; KS.Enabled = true; BlF.Enabled = true; ShD.Enabled = false; Pm.Enabled = false;
                ARSettings.Instance.Spec = "Combat"; }
            else if (Sp.Text == "Sublety")
            {
                VD.Enabled = false; AR.Enabled = false; KS.Enabled = false; BlF.Enabled = false; ShD.Enabled = true; Pm.Enabled = true;
                ARSettings.Instance.Spec = "Sublety"; }
            else
            { VD.Enabled = false; AR.Enabled = false; KS.Enabled = false; ShD.Enabled = false; ARSettings.Instance.Spec = null; }
        }

        private void SCP_CheckedChanged(object sender, EventArgs e)
        {
            if (SCP.Checked == true)
            {
                ARSettings.Instance.SpendCP = true;
            }
            else
            {
                ARSettings.Instance.SpendCP = false;
            }
        }

        private void eFT_CheckedChanged(object sender, EventArgs e)
        {
            if (eFT.Checked == true)
            {
                ARSettings.Instance.FaceTarget = true;
            }
            else
            {
                ARSettings.Instance.FaceTarget = false;
            }
        }

        private void Ru_CheckedChanged(object sender, EventArgs e)
        {
            if (Ru.Checked == true)
            {
                ARSettings.Instance.Rupture = true;
            }
            else
            {
                ARSettings.Instance.Rupture = false;
            }
        }

        private void Pr_CheckedChanged(object sender, EventArgs e)
        {
            if (Pr.Checked == true)
            {
                ARSettings.Instance.Preparation = true;
            }
            else
            {
                ARSettings.Instance.Preparation = false;
            }
        }

        private void BlF_CheckedChanged(object sender, EventArgs e)
        {
            if (BlF.Checked == true)
            {
                ARSettings.Instance.BladeFlurry = true;
            }
            else
            {
                ARSettings.Instance.BladeFlurry = false;
            }
        }

        private void Pm_CheckedChanged(object sender, EventArgs e)
        {
            if (Pm.Checked == true)
            {
                ARSettings.Instance.Premeditation = true;
            }
            else
            {
                ARSettings.Instance.Premeditation = false;
            }
        }
     }
   }